/**
 * 权限分类列表项
 */
interface AuthorizationTypeListItemResponse {
    /**
     * 标识符
     */
    id: string;
    /**
     * 序号
     */
    index: number;
    /**
     * 分类名称
     */
    name: string;
    /**
     * 权限分类级别
     */
    level: string;
}

/**
 * 权限分类详细
 */
interface AuthorizationTypeDetailResponse extends BaseResponse {
    /**
     * 权限分类名称
     */
    name: string;
    /**
     * 权限分类级别
     */
    level: string;
}

/**
 * 权限分类服务
 */
interface IAuthorizationTypeService {
    /**
     * 获取列表
     * v1.0
     * @param name 权限分类名称
     */
    getList(name: string, skip: number, count: number): ng.IHttpPromise<ListResponse<AuthorizationTypeListItemResponse>>;

    /**
     * 获取详细
     * v1.0
     * @param id 权限分类编号
     */
    getDetail(id: string): ng.IHttpPromise<AuthorizationTypeListItemResponse>;

    /**
     * 添加权限分类
     * v1.0
     * @param name 查询的分类名称
     * @param name 权限分类名称
     * @param level 权限分类级别
     */
    add(name: string, level: string): ng.IHttpPromise<BaseResponse>;

    /**
     * 编辑权限分类
     * v1.0
     * @param id 权限分类编号
     * @param name 查询的分类名称
     * @param name 权限分类名称
     * @param level 权限分类级别
     */
    edit(id: string, name: string, level: string): ng.IHttpPromise<BaseResponse>;

    /**
     * 删除权限分类
     * v1.0
     * @param id 权限分类编号
     */
    delete(id: string): ng.IHttpPromise<BaseResponse>;
}

class authorizationTypeService implements IAuthorizationTypeService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getList(name: string, skip: number, count: number): ng.IHttpPromise<ListResponse<AuthorizationTypeListItemResponse>> {
        return this.http<ListResponse<AuthorizationTypeListItemResponse>>({
            method: "GET",
            url: this.route.getUrl("authorizationType?name={{name}}&skip={{skip}}&count={{count}}", {
                name: name,
                skip: skip,
                count: count
            })
        });
    }

    getDetail(id: string): ng.IHttpPromise<AuthorizationTypeListItemResponse> {
        return this.http<AuthorizationTypeListItemResponse>({
            method: "GET",
            url: this.route.getUrl("authorizationType/{{id}}", {
                id: id
            })
        });
    }

    add(name: string, level: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "POST",
            url: this.route.getUrl("authorizationType"),
            data: {
                name: name,
                level: level
            }
        });
    }

    edit(id: string, name: string, level: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "PUT",
            url: this.route.getUrl("authorizationType/{{id}}", {
                id: id
            }),
            data: {
                name: name,
                level: level
            }
        });
    }

    delete(id: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "DELETE",
            url: this.route.getUrl("authorizationType/{{id}}", {
                id: id
            })
        });
    }
}

angular.module("authorizationTypeService",[]).service("authorizationTypeService",['$http','routeService',authorizationTypeService]);